package com.gx.dal.mapper;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gx.dal.dataobj.SysUserDo;
import org.apache.ibatis.annotations.Mapper;

/**
 * 用户信息表 Mapper
 *
 * @author liu-pj
 * @since 2024-03-26 11:43
 */
@Mapper
public interface SysUserMapper extends BaseMapper<SysUserDo> {
    default Long findUserCount(String account, String phone, Object id) {
        LambdaQueryWrapper<SysUserDo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.ne(ObjectUtil.isNotNull(id), SysUserDo::getId, id);
        queryWrapper.and(w -> {
            w.eq(StrUtil.isNotBlank(account), SysUserDo::getAccount, account)
                    .or()
                    .eq(StrUtil.isNotBlank(phone), SysUserDo::getPhone, phone);
        });
        return this.selectCount(queryWrapper);
    }

    default SysUserDo selectByAccount(String account){
        LambdaQueryWrapper<SysUserDo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(StrUtil.isNotBlank(account), SysUserDo::getAccount, account);
        SysUserDo sysUserDo = this.selectOne(wrapper);
        return sysUserDo;
    }
}
